package yxy.cherry.battle.module.selector;

import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.Team;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Set;

/**
 * @ClassName TargetSelector_27_血量百分比排序
 * @Author jingtao-zheng
 * @Date 2022/8/3 9:57
 * @Version 1.0
 **/
@TargetSelectorType(Type = 27)
public class TargetSelector_27_血量百分比排序 extends TargetSelector {
    @Override
    public Set<Fighter> target(Fighter actor, Team team, int param1, int param2) {
        ArrayList<Fighter> list = sort血量万分值(team);

        return getSpecialFighter(actor,list,param1,param2);
    }

    private ArrayList<Fighter> sort血量万分值(Team team) {
        ArrayList<Fighter> list = new ArrayList<>();
        for (Fighter fighter : team.getFighters()) {
            if (fighter.is活着()) {
                list.add(fighter);
            }
        }

        list.sort(new Comparator<Fighter>() {

            @Override
            public int compare(Fighter o1, Fighter o2) {

                if (!o1.is活着()) {
                    return -1;
                }
                int value = o1.get血量万分值() > o2.get血量万分值() ? 1 : -1;
                if (o1.get血量万分值() == o2.get血量万分值()) {
                    value = o2.get血量万分值() > o1.get血量万分值() ? 1 : -1;
                    return value;
                }
                return value;
            }
        });
        return list;
    }
}
